import store from '../../store'
const baseUrl = 'https://www.yuxianyun.com'  //新正式服 
export function request(configData) {  
	const token = uni.getStorageSync('token');
	configData.url = baseUrl+configData.url;
	if(configData.data) {
		configData.data.sessionid = token
	} else {
		configData.data = { sessionid: token }
	}
    return new Promise((resolve, reject) => {
        uni.request(configData).then((response) => {
			let [error, res] = response;	
			store.commit('setCode',res.data.code)
			if(res.data.status == 1) {
				resolve(res.data);
			} else if(res.data.status == 0) {
				setTimeout(() => {
					uni.showToast({
						title: res.data.message,
						icon: 'none'
					})
				}, 200)
				reject()
			}else if(res.data.status == -1){
				uni.removeStorageSync('token')
				uni.removeStorageSync('is_admin')
				uni.showToast({
					title: '请登录',
					icon: 'none'
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/home/index'
					});
				}, 600)
			}
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
    });
}

export {
	baseUrl
}